﻿using System;
using PSE.Deployment.Engine;
using PSE.Deployment.Engine.CustomEventArgs;
using PSE.Deployment.Engine.Enums;
using PSE.Deployment.Engine.Interfaces;
using PSE.Deployment.SetupBase.UI;

namespace PSE.Deployment.SetupBase.Steps
{
    public class UpdateInfo : BaseStep
    {
        private UpdateInformation _updateInfo;
        public StepNavigationAction NavigationAction { get; protected set; }

        public UpdateInfo(IStepGroup parent)
            : base(parent)
        {
            this.Id = "UpdateInfo";
            this.Description = "UpdateInfo";
            this.ErrorBehavior = StepErrorBehavior.CancelParent;
            this.NavigationBehavior = StepNavigationBehavior.NextCancel;

            this.ExecutionFinished += new EventHandler<ExecutionFinishedEventArgs>(UpdateInfo_ExecutionFinished);
        }

        void UpdateInfo_ExecutionFinished(object sender, ExecutionFinishedEventArgs e)
        {
            e.NavigationAction = this.NavigationAction;
        }

        public override void Execute()
        {
            _updateInfo = new UpdateInformation();
            _updateInfo.ShowDialog();
            this.NavigationAction = _updateInfo.NavigationAction.GetValueOrDefault();
        }

        public override void Undo()
        {
            if (_updateInfo != null)
                _updateInfo.Close(false);
        }
    }
}
